
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.Managers;
using Tathata.Common.Utils;

namespace Tathata.Web.Administration
{
    public partial class Administration_LanguageDetails : BaseNopAdministrationPage
    {
        private void BindData()
        {
            Language language = LanguageManager.GetByLanguageID(this.LanguageID);
            if (language != null)
            {
                this.txtName.Text = language.Name;
                this.txtLanguageCulture.Text = language.LanguageCulture;
                this.cbPublished.Checked = language.Published;
                this.txtDisplayOrder.Value = language.DisplayOrder;
            }
            else
                Response.Redirect("Languages.aspx");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.BindData();
            }
        }

        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    Language language = LanguageManager.GetByLanguageID(this.LanguageID);

                    if (language != null)
                    {
                        language = LanguageManager.UpdateLanguage(language.LanguageID, txtName.Text, txtLanguageCulture.Text,
                          cbPublished.Checked, txtDisplayOrder.Value);
                        Response.Redirect("LanguageDetails.aspx?LanguageID=" + language.LanguageID.ToString());
                    }
                    else
                        Response.Redirect("Languages.aspx");
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                LanguageManager.DeleteLanguage(this.LanguageID);
                Response.Redirect("Languages.aspx");
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }

        public int LanguageID
        {
            get
            {
                return CommonHelper.QueryStringInt("LanguageID");
            }
        }
    }
}
